using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace LowLevelGraphics.ImageAcquiring
{
    public class SelectablePictureBoxImageAcquiring : PictureBox
    {
        public SelectablePictureBoxImageAcquiring()
        {
            SetStyle(ControlStyles.Selectable, true);
            this.TabStop = true;
        }

        protected override void OnMouseDown(MouseEventArgs args)
        {
            base.OnMouseDown(args);
            this.Focus();
        }

        protected override void OnKeyPress(KeyPressEventArgs args)
        {
            if (args.KeyChar == '\r')
            {
                OnClick(EventArgs.Empty);
            }
            else
            {
                base.OnKeyPress(args);
            }
        }

        protected override void OnEnter(EventArgs args)
        {
            base.OnEnter(args);
            this.Invalidate();
        }

        protected override void OnLeave(EventArgs e)
        {
            base.OnLeave(e);
            this.Invalidate();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (this.Focused)
            {
                Graphics grfx = e.Graphics;
                grfx.DrawRectangle(new Pen(Brushes.Black, grfx.DpiX / 12),
                this.ClientRectangle);
            }
        }
    }
}
